﻿
Ext.define('app.controller.App', {
    extend: 'Ext.app.Controller',
    alias: 'controller.app',
    views: [
        'app.main.region.Center'
    ],
    routes: {
        'home': {
            action: 'onHome'
        },
        'app.prm.detail.Index/:id': {
            action: 'onPrmDetail'
        },
        'openmenu/:module': {
            action: 'onOpenMenu'
        },
        'app.prm.document.Index/:id': {
            action: 'onOpenDocument'
        },
        'app.prm.detail.Discuss/:id': {
            action: 'onOpenDiscuss'
        },
        'app.prm.detail.CMOProgress/:id': {
            action: 'onOpenCMOProgress'
        },
        'app.prm.synth.Index/:id': {
            action: 'onOpenSynth'
        },
        'app.prm.product.Detail/:id': {
            action: 'onOpenProductDetail'
        },
        'app.prm.project.PrmApply': {
            action: 'onOpenPrmApply'
        },
        'app.prm.document.Trash/:id': {
            action: 'onOpenTrash'
        },
        'app.main.home.todo/:id': {
            action: 'onOpenTodo'
        }
    },
    init: function () {
        this.addRef([{
            ref: 'maincenter',
            selector: '[xtype=maincenter]'
        }]);
        this.callParent();
    },
    onOpenPrmApply: function () {
        var tabPanel = this.getMaincenter();
        tabPanel.newDetailTab('prmApply', "app.prm.project.PrmApply", "项目查看申请");
    }
    ,
    onPrmDetail: function (id) {
        var tabPanel = this.getMaincenter();
        var projectName = Ext.util.Cookies.get("projectinfo" + id);
        tabPanel.newDetailTab(id, "app.prm.detail.Index", projectName);
    },
    onOpenTodo: function (id) {
        var tabPanel = this.getMaincenter();
        var projectName = Ext.util.Cookies.get("projectinfo" + id);
        tabPanel.newDetailTab(id, "app.prm.detail.Index", projectName, '项目任务');
    },
    onOpenDocument: function (id) {
        var tabPanel = this.getMaincenter();
        var text = Ext.util.Cookies.get("projectdocument" + id);
        tabPanel.newDetailTab(id, "app.prm.document.Index", text);
    },
    onOpenDiscuss: function (id) {
        var tabPanel = this.getMaincenter();
        var text = Ext.util.Cookies.get("projectdiscuss" + id);
        tabPanel.newDetailTab(id, "app.prm.detail.Discuss", text);
    },
    onOpenCMOProgress: function (id) {
        var tabPanel = this.getMaincenter();
        var text = Ext.util.Cookies.get("projectcmoprogress" + id);
        tabPanel.newDetailTab(id, "app.prm.detail.CMOProgress", text);
    },
    onOpenTrash: function (id) {
        var tabPanel = this.getMaincenter();
        var text = Ext.util.Cookies.get("projectdocument" + id);
        tabPanel.newDetailTab(id, "app.prm.document.Trash", text + "回收站");
    },
    onOpenMenu: function (module) {

        var text = Ext.util.Cookies.get(module);
        var url = module.split('-').join('.')

        var tabPanel = this.getMaincenter();
        var _itemid = 'm_' + new Date().getTime();

        tabPanel.newTab(_itemid, url, text);
    },
    onOpenSynth: function (id) {
        var tabPanel = this.getMaincenter();
        var text = Ext.util.Cookies.get("projectsynth" + id);
        tabPanel.newDetailTab(id, "app.prm.synth.Index", text);
    },
    onOpenProductDetail: function (id) {
        var tabPanel = this.getMaincenter();
        var text = Ext.util.Cookies.get("productinfo" + id);
        tabPanel.newDetailTab(id, "app.prm.product.Detail", text);
    },
    onHome: function () { }
});
